<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 和为s的两个数字 -->
    <script>
      var twoSum = (nums, target) => {
        let [left, right] = [0, nums.length - 1]
        while (left < right) {
          sum = nums[left] + nums[right]
          if (sum > target) {
            // 太大了，右指针左移
            right--
          } else if (sum < target) {
            // 太小了，左指针右移
            left++
          } else {
            // 找到，直接返回两个数
            return [nums[left], nums[right]]
          }
        }
      }
      console.log(twoSum([2, 7, 11, 15], 9))
    </script>
  </body>
</html>
